import request from '@/utils/request'

enum Api {
  list = '/man/algCategory/page',
  save = '/man/algCategory/add',
  edit = '/man/algCategory/edit',
  delOne = '/man/algCategory/del',
  upload = '/man/algCategory/upload'
}

/**
 * 上传json文件
 * @param data
 */
export const upload = async (data: FormData) => {
  return await request.post(Api.upload, {
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 列表
 * @param data
 */
export const list = async (data: {
  pageNum: number
  pageSize: number
  instanceName: string
  categoryName?: null | string
}) => {
  return await request.post(Api.list, { data })
}

/**
 * 新增/修改
 * @param data
 * @param isUpdate true 修改 / false 新增
 */
export const save = async (
  data: {
    id?: undefined | number
    jsonName: string
    apiToken: string
    apiAddress: string
    categoryName?: undefined | string
    algCategoryInstanceVoList: any[]
  },
  isUpdate: boolean
) => {
  const url = isUpdate ? Api.edit : Api.save
  return await request.post(url, { data })
}

/**
 * 删除
 * @param id
 */
export const delOne = async (id: number) => {
  return await request.get(`${Api.delOne}/${id}`)
}
